const root = {
    val: 'A',
    left: {
        val: 'B',
        left: {
            val: 'D'
        },
        right: {
            val: 'E'
        },
    },
    right: {
        val: 'C',
        left: {
            val: 'F',
        }
    }
}
var levelOrder = function (root) {
  const queue = []
  queue.push(root)
  const res = []
  while (queue.length) {
    const arr = []
    const len = queue.length
    for (let i = 0; i < len; i++) {
      const top = queue.shift()
      arr.push(top.val)
      if (top.left) {
        queue.push(top.left)
      }
      if (top.right) {
        queue.push(top.right)
      }
    }
    res.push(arr)
  }
  return res
}
console.log(levelOrder(root))
